package cn.flying.cloud.message.view;

import javax.annotation.Resource;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.flying.cloud.message.bo.MsgTemplateBo;
import cn.flying.cloud.message.service.MsgTemplateService;
import cn.flying.cloud.system.common.service.CodeService;

/**
 * 消息模板
 *
 * @author: admin
 * @date: 2024年12月26日 21:34
 * @version: 1.0
 */
@Controller
@RequestMapping("message/template")
public class MsgTemplateViewController {

    @Resource
    private CodeService codeService;
    @Resource
    private MsgTemplateService msgTemplateService;

    /**
     * 列表页面
     *
     * @return
     */
    @RequestMapping("index")
    public String list(Model model) {
        Map<String, String> statusList = codeService.getCodeList("status");
        model.addAttribute("statusList", statusList);
        Map<String, String> modeList = codeService.getCodeList("msg_mode");
        model.addAttribute("modeList", modeList);
        Map<String, String> serviceNameList = codeService.getCodeList("service_name");
        model.addAttribute("serviceNameList", serviceNameList);
        return "message/template/index";
    }

    /**
     * 新增/修改页面
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("turn/edit")
    public String turnEdit(Long id, Model model) {
        Map<String, String> modeList = codeService.getCodeList("msg_mode");
        model.addAttribute("modeList", modeList);
        Map<String, String> serviceNameList = codeService.getCodeList("service_name");
        model.addAttribute("serviceNameList", serviceNameList);
        if (null != id) {
            model.addAttribute("template", msgTemplateService.getById(id));
        } else {
            MsgTemplateBo template = new MsgTemplateBo();
            template.setStatus("Y");
            model.addAttribute("template", template);
        }
        return "message/template/edit";
    }
}
